Post

Replies

Boosts

Views

Created

Swift: AVAssetWriter output issue with duration.
I am using AVAssetWriter to write data captured using AVCaptureOutput. I can able to create the output mp4 but the mp4 generated duration is not in sync with actual frames captured. For eg: If I recorded video for 30 sec with 30fps (900 frames) then the duration of the output mp4 files is 30.05 which is not the actual one expected. But the same test If I did without appending audio then I am getting the exact duration of 30.0sec. Here is my code used. Why the durations are mismatching with and without audio? This .05 seconds is affecting with bigger impact in total duration when I try to merge large number of files. public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { guard CMSampleBufferDataIsReady(sampleBuffer) else { return } if output is AVCaptureVideoDataOutput && videoWriterInput.isReadyForMoreMediaData { videoWriterInput.append(sampleBuffer) }else if output is AVCaptureAudioDataOutput && audioWriterInput.isReadyForMoreMediaData { audioWriterInput.append(sampleBuffer) } } func setupWriter() { let url = "URL" videoWriter = try AVAssetWriter(url: url, fileType: AVFileType.mp4) //Add video input videoWriterInput = AVAssetWriterInput(mediaType: AVMediaType.video, outputSettings: [ AVVideoCodecKey: AVVideoCodecType.h264, AVVideoWidthKey: frameSize.width, AVVideoHeightKey: frameSize.height, AVVideoCompressionPropertiesKey: [ AVVideoAverageBitRateKey: 1000000 * bitRate //16 //2300000, ], ]) videoWriterInput.mediaTimeScale = CMTimeScale(bitPattern: 600) videoWriterInput.expectsMediaDataInRealTime = true if videoWriter.canAdd(videoWriterInput) { videoWriter.add(videoWriterInput) } //Add audio input audioWriterInput = AVAssetWriterInput(mediaType: AVMediaType.audio, outputSettings: [ AVFormatIDKey: kAudioFormatMPEG4AAC, AVNumberOfChannelsKey: 1, AVSampleRateKey: 44100, AVEncoderBitRateKey: 64000, ]) audioWriterInput.expectsMediaDataInRealTime = true if videoWriter.canAdd(audioWriterInput) { videoWriter.add(audioWriterInput) } videoWriter.startWriting() }
0
0
828
Dec ’22
Multipeer Connetivity iOS is too slow to transfer files
I have an application which transfer video files from one device to another using Multipeer connectivity. But it is taking too much time even though the file size are smaller. I am using the below method to transfer file self.session.sendResource(at: url, withName: name, toPeer: peerID) Here url is the path of a video file(mp4) which is in temp directory. The receiving code snippets are public func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) { } public func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL?, withError error: Error?) { } Is there any reason for the slowness ? I tried with multiple WiFi routers but same issue. I also tried enabling and disabling blootooth as some of the old post mentioned that it was one of the reason.
4
0
1.3k
Oct ’22
SWIFT: Unable to downlaod larger files from aws bucket using transfer utility
I have a swift application and there is a requirement to download mp4 files from AWS bucket. I'm able to download file with smaller sizes but can't download files above particular sizes say 2GB and its depend on device too. While trying to download such kind of files, getting the below error `Failed with error: Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." Also noticed that when trying to download 140 files with size of 100 MB each only able to download a maximum of approximately 100 files, after that I got the same error. Is there any such limit on iOS for downloading files.
3
0
1.2k
Oct ’22